package com.hospital.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.model.Department;
import com.hospital.util.DbUtil;
@WebServlet("/manage/DepartmentByAdminServlet")
public class DepartmentByAdminServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String method = request.getParameter("method");
		if ("add".equals(method)) {
			String name = request.getParameter("name").trim();
			String type = request.getParameter("type").trim();
			String flag = request.getParameter("flag").trim();
			String description = request.getParameter("description");
			String sql = "insert into t_department(name , type, flag, description) values('"
					+ name +"', '" + type + "', '" + flag + "','" + description + "')";
					DbUtil.add_modify(sql);
		} else if ("del".equals(method)) {
			String[] deptId = request.getParameterValues("selectFlag");
			DbUtil.deldeptId("t_department", deptId);
		} else if ("modify".equals(method)) {
			String deptId = request.getParameter("deptId");
			String flag = request.getParameter("flag").trim();
			String description = request.getParameter("description");
			String sql = "update t_department set flag = '" + flag + "', description = '" + description + "' where deptId = " + deptId;
			DbUtil.add_modify(sql);
		}
		request.getRequestDispatcher("/manage/departmentByadmin_info_manage.jsp").forward(request, response);
	}
}